package com.atguigu.srb.core.controller.api;


import com.atguigu.common.exception.BusinessAssert;
import com.atguigu.common.result.R;
import com.atguigu.common.result.ResponseEnum;
import com.atguigu.srb.core.pojo.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.atguigu.srb.utils.JwtUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author 龙龙龙
 * @since 2022-01-21
 */
@RestController
@RequestMapping("/api/core/borrower")
@Slf4j
public class ApiBorrowerController {

    @Autowired
    private BorrowerService borrowerService;
    //
    @GetMapping("/auth/getBorrowerStatus")
    @ApiOperation("获取借款人认证状态")
    public R getBorrowerStatus(HttpServletRequest request){
        String token = request.getHeader("token");
        BusinessAssert.notNull(token, ResponseEnum.WEIXIN_FETCH_ACCESSTOKEN_ERROR);
        Long userId = JwtUtils.getUserId(token);
       Integer status = borrowerService.getBorrowerStatus(userId);
        return R.ok().data("borrowerStatus",status);
    }

     @PostMapping("/auth/save")
    @ApiOperation("保存借款人信息")
    public R save(@RequestBody BorrowerVO borrowerVO, HttpServletRequest request){
        String token = request.getHeader("token");
        BusinessAssert.notNull(token, ResponseEnum.LOGIN_AUTH_ERROR);
        Long userId = JwtUtils.getUserId(token);
      Integer a = borrowerService.saveBorrower(userId,borrowerVO);
         return R.ok().message("信息提交成功");
    }



}

